package com.example.yuejian23.yuejian_23.activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.yuejian23.yuejian_23.Adapter.PeixunAdapter;
import com.example.yuejian23.yuejian_23.Adapter.PinglunAdapter;
import com.example.yuejian23.yuejian_23.Fragment.PeixunFragment;
import com.example.yuejian23.yuejian_23.R;
import com.example.yuejian23.yuejian_23.javaBean.HuodongBean;
import com.example.yuejian23.yuejian_23.javaBean.PeixunBean;
import com.example.yuejian23.yuejian_23.javaBean.PinglunBean;
import com.example.yuejian23.yuejian_23.javaBean.ShaituBean;
import com.example.yuejian23.yuejian_23.service.HomeService;
import com.example.yuejian23.yuejian_23.service.ShaituService;
import com.squareup.picasso.Picasso;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class ShaituActivity extends AppCompatActivity {
    String shaitu;
    TextView name;
    ImageView shaitu_thumb,shaitu_pic,pingjia;
    TextView name_title;
    RecyclerView recyclerView;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_shaitu);
        intview();

        Bundle bundle = this.getIntent().getExtras();
        shaitu = bundle.getString("shaituid");
        //intnt传参

        getjulebudetil();
    }

    public void getjulebudetil() {
        Retrofit retrofit=new Retrofit.Builder()
                .baseUrl("http://115.159.93.244/new18yuejian/api.php/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        Call<PinglunBean> call = retrofit.create(ShaituService.class).getxiang(shaitu);
        call.enqueue(new Callback<PinglunBean>() {
            @Override
            public void onResponse(Call<PinglunBean> call, Response<PinglunBean> response) {
                PinglunBean myping = response.body();
                name.setText(myping.getUname());
                name_title.setText(myping.getPtext());
                Picasso.with(ShaituActivity.this).load("http://115.159.93.244/new18yuejian/Public/upload/"+myping.getPostfile()).into(shaitu_pic);
                Picasso.with(ShaituActivity.this).load("http://115.159.93.244/new18yuejian/Public/upload/"+myping.getUserpic()).into(shaitu_thumb);

                recyclerView.setAdapter(new PinglunAdapter(ShaituActivity.this,myping.getReplay()));
            }

            @Override
            public void onFailure(Call<PinglunBean> call, Throwable t) {

            }
        });

    }


    private void intview() {
        recyclerView = (RecyclerView) findViewById(R.id.ping);
        recyclerView.setLayoutManager(new LinearLayoutManager(ShaituActivity.this));
        name = (TextView) findViewById(R.id.name);
        shaitu_thumb = (ImageView) findViewById(R.id.shaitu_thumb);
        name_title = (TextView) findViewById(R.id.name_title);
        shaitu_pic = (ImageView) findViewById(R.id.shaitu_pic);
        pingjia = (ImageView) findViewById(R.id.pingjia);
        pingjia.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();

                Bundle bundle = new Bundle();
                bundle.putString("shaituid",shaitu);
                intent.putExtras(bundle);

                intent.setClass(ShaituActivity.this,PingjiaActivity.class);
                startActivity(intent);
            }
        });//跳转

    }
}
